package com.zc.exception;

import com.zc.Enum.ErrorEnum;

import java.text.MessageFormat;

/**
 * 自定义异常
 * 目的：
 * 统一处理异常信息
 * 便于解耦，可以在拦截器，控制层，业务曾去使用
 */
public class BusinessException extends RuntimeException {

    private String errorCode;
    private String errorMsg;


    public BusinessException(ErrorEnum errorEnum) {
        super(errorEnum.getErrorMsg());
        this.errorCode = errorEnum.getErrorCode();
        this.errorMsg = errorEnum.getErrorMsg();
    }

    public BusinessException(ErrorEnum errorEnum, String... params) {
        super(errorEnum.getErrorMsg());
        this.errorCode = errorEnum.getErrorCode();
        this.errorMsg = MessageFormat.format(errorEnum.getErrorMsg(), params);
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }


}
